﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace ApplicationServer
{
    public class TestMembershipProvider : System.Web.Security.MembershipProvider
    {
        static readonly MembershipUser MembershipUser = new MembershipUser(
            "TestMembershipProvider", 
            "test", 
            null, 
            "test@aastmt.edu",
            string.Empty,
            string.Empty,
            true, 
            false,
            new DateTime(2011,05,15),
            new DateTime(2011,05,20),
            new DateTime(2011,05,20),
            new DateTime(2011,05,20),
            new DateTime(2011,05,16));
        static readonly MembershipUserCollection MembershipUserCollection = new MembershipUserCollection();

        static TestMembershipProvider()
        {
            //MembershipUserCollection.Add(MembershipUser);
        }

        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            status = MembershipCreateStatus.UserRejected;
            return null;
        }

        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            return false;
        }

        public override string GetPassword(string username, string answer)
        {
            return string.Empty;
        }

        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            return false;
        }

        public override string ResetPassword(string username, string answer)
        {
            return string.Empty;
        }

        public override void UpdateUser(MembershipUser user)
        {
            return;
        }

        public override bool ValidateUser(string username, string password)
        {
            return (string.Compare(username, MembershipUser.UserName , true) == 0 && string.Compare(password, "1234", true) == 0);
        }

        public override bool UnlockUser(string userName)
        {
            return true;
        }

        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            return MembershipUser;
        }

        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            return MembershipUser;
        }

        public override string GetUserNameByEmail(string email)
        {
            return null;
        }

        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            return false;
        }

        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            totalRecords = 1;
            return MembershipUserCollection;
        }

        public override int GetNumberOfUsersOnline()
        {
            return 1;
        }

        public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            if (string.Compare(MembershipUser.UserName, usernameToMatch, true)==0)
            {
                totalRecords = 1;
                return MembershipUserCollection;
            }
            else
            {
                totalRecords = 0;
                return null;
            }
        }

        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            totalRecords = 0;
            return null;
        }

        public override bool EnablePasswordRetrieval
        {
            get { return false; }
        }

        public override bool EnablePasswordReset
        {
            get { return false; }
        }

        public override bool RequiresQuestionAndAnswer
        {
            get { return false; }
        }

        public override string ApplicationName { get; set; }

        public override int MaxInvalidPasswordAttempts
        {
            get { return 1000; }
        }

        public override int PasswordAttemptWindow
        {
            get { return 1000; }
        }

        public override bool RequiresUniqueEmail
        {
            get { return false; }
        }

        public override MembershipPasswordFormat PasswordFormat
        {
            get { return MembershipPasswordFormat.Clear; }
        }

        public override int MinRequiredPasswordLength
        {
            get { return 1; }
        }

        public override int MinRequiredNonAlphanumericCharacters
        {
            get { return 0; }
        }

        public override string PasswordStrengthRegularExpression
        {
            get { return null; }
        }
    }
}